mod.dir = '/home1/99/jc152199/brt/FINALMODELS50PERCENTFORTESTING/'
wd = '/home1/99/jc152199/brt/'
setwd(wd)

source('brt.functions.R.cjsedit.r')

library('gbm')

mods = list.files(mod.dir,recursive=T,full.names=T, pattern='Rdata')
test.files = list.files(mod.dir, recursive=T, full.names=T,pattern='Test_Data')

mod.names = list.files(mod.dir, recursive=T, pattern='.Rdata')

i=1

out.data = NULL

### cycle through models and extract summary info

for (mod in mods)

	{

	load(paste(mod))
	
	if(i %in% c(seq(1,length(mods),2))==T)
	
	{
	
	#test.data = read.csv(paste(test.files[i]),header=T)
	
	#check = gbm.predict.grids(max.brt.gbm.step, test.data, want.grids = F)
	
	t.data = data.frame(param.set = substr(mod.names[i],4,5), type = substr(mod,nchar(mod)-13,nchar(mod)-11), tree.complexity = max.brt.gbm.step$gbm.call$tree.complexity, learning.rate = max.brt.gbm.step$gbm.call$learning.rate, cv.dev.mean = max.brt.gbm.step$cv.statistics$deviance.mean, cv.dev.se = max.brt.gbm.step$cv.statistics$deviance.se)
	
	}
	
	if(i %in% c(seq(2,length(mods),2))==T)
	
	{
	
	#test.data = read.csv(paste(test.files[i]),header=T)
	
	#check = gbm.predict.grids(max.brt.gbm.step, test.data, want.grids = F)
	
	t.data = data.frame(param.set = substr(mod.names[i],4,5), type = substr(mod,nchar(mod)-13,nchar(mod)-11), tree.complexity = min.brt.gbm.step$gbm.call$tree.complexity, learning.rate = min.brt.gbm.step$gbm.call$learning.rate, cv.dev.mean = min.brt.gbm.step$cv.statistics$deviance.mean, cv.dev.se = min.brt.gbm.step$cv.statistics$deviance.se)
	
	}
	
	out.data = rbind(out.data,t.data)
	
	cat('\n',(i/length(mods))*100)
	
	i=i+1
	
	
	
	}
	
# Close loop

write.csv(out.data,paste(mod.dir,'Comparison.csv',sep=''),row.names=F)
	
	
	



